<include file="StoreZT:header"/>
<link rel="stylesheet" href="/assets/public/mobiscroll/css/mobiscroll.custom-3.0.0-beta2.min.css">
<div class="wraper space">
	<a href="/base/storeZT/address/cart_id/{BEESCRM:$cart_id}/store_id/{BEESCRM:$storeId}/type/1003/picked/{BEESCRM:$picked}" class="list-info status tb-mode">
		<p class="tb-cell"><span class="iconfont icon-location"></span></p>
		<div class="tb-cell">
			<if condition="$data['address']['real_name']">
				{BEESCRM:$data.address.real_name}&nbsp;&nbsp;&nbsp;&nbsp;
			</if>
			<if condition="$data['address']['mobile']">
				{BEESCRM:$data.address.mobile}&nbsp;&nbsp;&nbsp;&nbsp;
			</if>
			<if condition="$picked eq 0 and $data['address']['address_id'] gt 0">
				<if condition="$data['address']['address_detail']">
					{BEESCRM:$data.address.address_detail}
				<else/>
					缺少地址信息，请完善
				</if>
			</if>
			<if condition="$data['address']['address_id'] lt 1 and $picked eq 0">
				请添加地址
			<elseif condition="$data['address']['address_id'] lt 1 and $picked eq 1"/>
				请添加联系方式
			</if>
		</div>
		<div class="tb-cell"><span class="iconfont icon-you pull-right"></span></div>
	</a>
    <div class="order-list">
        <a href="{BEESCRM::U('base/storeZT/index',array('store_id'=>$storeId))}" class="shop">
        	<span class="iconfont icon-dianpu"></span>
        	{BEESCRM:$data.store_name} <span class="iconfont icon-you"></span>
        </a>
		<volist name="data['cart']" id="vo">
	        <a href="#" class="list-info order text-black">
				<div class="tb-cell product-img">
					<div><img src="{BEESCRM:$vo.goods.goods_thumb}"></div>
				</div>
	            <div class="product-info">
	                <p>{BEESCRM:$vo.goods.goods_name}</p>
	                <p class="prize"><span>￥{BEESCRM:$vo.price}</span> <span>X{BEESCRM:$vo.goods_num}</span></p>
					<p class="text-12">
						<if condition="$vo['goods']['discount'] gt 0">
							<span class="product-label label-bg-red">{BEESCRM:$vo.goods.discount}折</span>
						</if>
						<if condition="$vo['goods']['picked'] eq 1">
							<span class="product-label">自提</span>
						<else/>
							<span class="product-label">快递</span>
						</if>
						<if condition="$store_type eq 2">
							<if condition="$vo['goods']['pay_alipay_id'] neq $alipayId">
								<span class="product-label">厂家直营</span>
							</if>
						<else/>
							<if condition="$vo['goods']['pay_wechat_id'] neq $wechatId">
								<span class="product-label">厂家直营</span>
							</if>
						</if>
					</p>
	                <if condition="$vo['goods_spec'] neq ''">
	                <p>规格：{BEESCRM:$vo.goods_spec}</p>
	                </if>
	            </div>
	        </a>
			<if condition="$picked eq 1">
				<div class="list">提取地点：{BEESCRM:$vo.since_address}</div>
				<div class="list">商家规则：{BEESCRM:$vo.goods.picked_rule}</div>
			</if>
        </volist>
    </div>

	<div class="order-info">
		<textarea placeholder="给卖家留言" class="leave-message" id="remark"></textarea>

		<div class="list">
			<p class="text-right">
				共 <span class="strong-red">{BEESCRM:$data.cart|count}</span> 件商品 &nbsp;&nbsp;&nbsp;
				<!--优惠：<span class="strong-red">￥{BEESCRM:$data.order.discount}</span>-->
			</p>
			<!--<p class="text-right">-->
				<!--合计：<span class="strong-red">￥{BEESCRM:$data.order.order_amount}</span></p>-->
		</div>
	</div>

    <div class="btn-box bottom clearfix">
        <p class="pull-left"><span class="account">合计：<span>￥{BEESCRM:$data.total_price}</span></span></p>
        <p class="pull-right"><a href="javascript:void(0)" class="btn pay" id="submit">确认下单</a></p>
    </div>
	<!--new-->
	<!--
	<div class="order-list">
		<a href="{BEESCRM::U('base/storeZT/index',array('store_id'=>$storeId))}" class="shop">
			<span class="iconfont icon-dianpu"></span>
			{BEESCRM:$data.store_name} <span class="iconfont icon-you"></span>
		</a>
		<volist name="data['order']['StoreOrderGoods']" id="vo">
			<a href="#" class="list-info order text-black">
				<div class="tb-cell product-img">
					<div><img src="{BEESCRM:$vo.goods_thumb}"></div>
				</div>
				<div class="product-info">
					<p>{BEESCRM:$vo.goods_name}</p>
					<p class="prize"><span>￥{BEESCRM:$vo.goods_price}</span> <span>X{BEESCRM:$vo.goods_num}</span></p>
					<p class="text-12"><span class="product-label label-bg-red">6折</span><span class="product-label">快递</span><span class="product-label">厂家自营</span></p>
					<if condition="$vo['spec'] neq ''">
						<p>规格：{BEESCRM:$vo.spec}</p>
					</if>
				</div>
			</a>
		</volist>
		<div class="list">
			<p class="text-right">
				共 <span class="strong-red">{BEESCRM:$data.order.StoreOrderGoods|count}</span> 件商品 &nbsp;&nbsp;&nbsp;
				优惠：<span class="strong-red">￥{BEESCRM:$data.order.discount}</span>
			</p>
			<p class="text-right">
				合计：<span class="strong-red">￥{BEESCRM:$data.order.order_amount}</span></p>
		</div>
	</div>
	-->

</div>
<include file="StoreZT:commonJs"/>
<script src="/assets/public/mobiscroll/mobiscroll.custom-3.0.0-beta2.min.js"></script>
<script>
	var currYear = (new Date()).getFullYear();
	var opt={};
	opt.date = {preset : 'date'};
	opt.datetime = {preset : 'datetime'};
	opt.time = {preset : 'time'};
	opt.default = {
		theme: 'ios', //皮肤样式
		display: 'bottom', //显示方式
		mode: 'scroller', //日期选择模式
		lang:'zh',
		startYear:currYear - 10, //开始年份
		endYear:currYear + 10 //结束年份
	};

	var optDateTime = $.extend(opt['datetime'], opt['default']);
	var optTime = $.extend(opt['time'], opt['default']);
	$("#date").mobiscroll(optDateTime).datetime(optDateTime);
</script>
<script type="text/javascript">
	$(function(){
		//确认付款
		$(document).on('click','#submit',function(){
			var remark=$('#remark').val();
			var cart_id = "{BEESCRM:$cart_id}";
			var address_id="{BEESCRM:$data['address']['address_id']}";
			var openId = "{BEESCRM:$openId}";
			$.ajax({
				url: "{BEESCRM::U('base/storeZT/createOrder',array('store_id'=>$storeId))}",
				type: 'POST',
				dataType: 'json',
				data: {cart_id: cart_id, address_id: address_id, remark: remark,openId:openId},
				success: function (data) {
					if (data.status == 'AS') {
						location.href = data.url;
					} else if (data.status == 'WS') {
						//微信支付
						if (typeof WeixinJSBridge == "undefined") {
							if (document.addEventListener) {
								document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
							} else if (document.attachEvent) {
								document.attachEvent('WeixinJSBridgeReady', jsApiCall);
								document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
							}
						} else {
							WeixinJSBridge.invoke(
								'getBrandWCPayRequest',
								$.parseJSON(data.url),
								function (res) {
									WeixinJSBridge.log(res.err_msg);
									if (res.err_msg == "get_brand_wcpay_request:ok") {
										paySuccess(data.order_id);
									} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
										$.alert('error', '你肯定不是真的想抛弃我们～');
										return false;
									} else {
										$.alert('error', '哎呀，网络不给力，小微又调皮了，咋们刷新再来一次');
										setTimeout("location.reload()", 2000);
										return false;
									}
								}
							);
						}
					} else if (data.status == 'S') {
						paySuccess(data.order_id);
					} else {
						swal("", data.message, "error");
					}
				}
			})
		});

		function paySuccess(order_id){
			var json={};
			json.url="{BEESCRM::U('base/storeZT/paysuccess',array('origin'=>$origin,'store_id'=>$storeId))}/order_id/"+order_id;
			$.getAjax(json,false,redirect);
		}

		function redirect(data){
			location.href=data.url;
		}
	});
</script>
<include file="StoreZT:footer" />
